<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item class="set_width">
					<el-input v-model="filters.name" placeholder="姓名"></el-input>
				</el-form-item>
				<el-form-item class="set_width">
					<el-select placeholder="性别" value="性别" v-model="filters.gender">
						<el-option label="男" value="0"></el-option>
						<el-option label="女" value="1"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item class="set_width">
					<el-select placeholder="级别" value="请选择" v-model="filters.level">
						<el-option v-for="level in relevel"
							:key="level.id"
							:label="level.dictName"
							:value="level.id">
						</el-option>
					</el-select>
					
				</el-form-item>
				<el-form-item class="set_width">
					<el-input v-model="filters.homeAddress" placeholder="居住地"></el-input>
				</el-form-item>
				<el-form-item class="set_width">
					<el-input v-model="filters.idNum" placeholder="身份证号"></el-input>
				</el-form-item>
				<el-form-item class="set_width">
					<el-input v-model="filters.certificateNum" placeholder="裁判证号"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="queryUsers">查询</el-button>
					<el-button type="success" v-on:click="resetquery">清空</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="users" highlight-current-row v-loading="listLoading"  style="width: 100%;">
			<el-table-column prop="name" label="姓名" width="100">
			</el-table-column>
			<el-table-column prop="gender" label="性别" width="80" :formatter="formatSex" sortable>
			</el-table-column>
			<el-table-column prop="birthday" label="生日" width="120" sortable>
			</el-table-column>
			<el-table-column prop="idNum" label="身份证号" width="100">
			</el-table-column>
			<el-table-column prop="level" label="级别" min-width="120" :formatter="formatReLevel" sortable>
			</el-table-column>
			<el-table-column prop="certificateNum" label="国际裁判号" min-width="120">
			</el-table-column>
			<el-table-column prop="homeAddress" label="居住地" min-width="140">
			</el-table-column>
			<el-table-column prop="mobile" label="联系电话" min-width="120">
			</el-table-column>
			<el-table-column label="操作" width="150">
				<template slot-scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)">查看</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<!-- <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button> -->
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import mycommon from  '../../common/enum'
	import { getReLeve , removeUser  } from '../../api/api';

	export default {
		data() {
			return {
				filters: {
					name: '',
					gender:'',
					level: '',
					homeAddress:'',
					idNum:'',
					certificateNum:''
				},
				relevel:[], // 裁判员等级
				releveldict:{}, // 裁判员等级词典 过滤器用
				users: [], // 表格数据
				total: 0, // 数据总条数
				page: 1, // 当前页面
				listLoading: false,
				sels: [],//列表选中列
				editLoading: false,
				addLoading: false,
			}
		},
		methods: {
			// formatSex: this.$filters.formatSex,
			formatReLevel (row) {
				return this.releveldict['lv'+row.level];
			},
  // 性别显示转换
			formatSex(row) {
				return row.gender == 0 ? '男' : row.gender == 1 ? '女' : '保密';
			},
			// 分页的切换事件
			handleCurrentChange(val) {
				this.page = val;
				this.getUsers();
			},
			//获取用户列表
			getUsers() {
				this.listLoading = true;
				let  useroption = {
					pageNum:this.page,
					pageSize:10,
					status: 0,
					delFlag:0,
					name: this.filters.name,
					gender: this.filters.gender,
					level: this.filters.level,
					homeAddress: this.filters.homeAddress,
					idNum: this.filters.idNum,
					certificateNum:this.filters.certificateNum

				};
				// 获取裁判员数据
				this.axios.get('/referee/manage/re/page', {params: useroption}).then( response => {
					this.listLoading = false;
					this.total = response.data.data.total;
					this.users = response.data.data.list;

				}).catch( error => {
					this.listLoading = false;
					console.log(error)
				})

				// getCaipanList(userdata).then(response =>{
				// 	console.log(response.data.data.list);
				// }).catch( error=>{
				// 	console.log(error);
				// })

				// getUserListPage(para).then((res) => {
				// 	this.total = res.data.total;
				// 	this.users = res.data.users;
				// 	this.listLoading = false;
				// });
				
			},
			// 查询裁判员
			queryUsers(){
				this.page = 0;
				this.getUsers();
			},
			// 清空查询条件
			resetquery(){
				// 清空搜索条件，重新查询所有裁判员
				this.filters = {
					name: '',
					gender:'',
					level: '',
					homeAddress:'',
					idNum:'',
					certificateNum:''
				};
				this.page = 0;
				this.getUsers();
			},
			// 删除
			handleDel: function (index, row) {
				this.$confirm('确认删除该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					let para = { id: row.id };
					removeUser(row.id).then((res) => {
						this.listLoading = false;
						if(res.data.code === '0000'){
							this.$message({
								message: '删除成功',
								type: 'success'
							});
						this.getUsers();
						}
						
					});
				}).catch(() => {

				});
			},
			// 跳转到编辑页面
			handleEdit: function (index, row) {
				console.log(row.id);
				this.$router.push({path: '/editcaipanyuan', query: { userId: row.id }});
				// this.editFormVisible = true;
				// this.editForm = Object.assign({}, row);
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			//批量删除
			batchRemove: function () {
				var ids = this.sels.map(item => item.id).toString();
				this.$confirm('确认删除选中记录吗？', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = { ids: ids };
					batchRemoveUser(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
						this.getUsers();
					});
				}).catch(() => {

				});
			},

		},
		mounted() {
			console.log(this);
			this.nations = mycommon.nations;
			this.getUsers();
			// 初始化裁判等级
			getReLeve()
			.then((res) => {
				if(res.data.code==='0000'){
					this.relevel = res.data.data.list.filter(level=>{
						return level.isDel === 0;
					});
					this.relevel.forEach(level => {
						if(level.isDel === 0){
							this.releveldict['lv'+ level.id] = level.dictName
						}
					});
				}
			}).catch((err) => {
				
			});
		}
	}

</script>

<style scoped>

</style>